package com.wwz.controller;

import cn.hutool.core.util.StrUtil;
import com.wwz.exception.CustomException;
import com.wwz.pojo.query.PersonQuery;
import com.wwz.result.Result;
import com.wwz.service.PersonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("person")
@Api(tags = "接口测试")
public class PersonController {

    @Resource
    private PersonService personService;

    @GetMapping("test")
    @ApiOperation("测试查询")
    public Result<?> get(){
        return Result.ok("测试");
    }

    @GetMapping("page")
    @ApiOperation("分页查询")
    public Result<?> page(PersonQuery query){
        return Result.ok(personService.toPage(query));
    }

    @DeleteMapping("delete/{id}")
    @ApiOperation("删除")
    public Result<?> delete(@PathVariable String id){
        if (StrUtil.isEmpty(id)){
            throw new CustomException("id不能为空");
        }
        personService.removeById(id);
        return Result.ok();
    }
}
